tinymce.PluginManager.add('margintop', function(editor, url) {
    var pluginName='段前距';
    var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
    var margintop_val = editor.getParam('margintop_val', '5px 10px 15px 20px 25px');

    editor.on('init', function() {
        editor.formatter.register({
        	margintop: {
                selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table',
                styles: { 'margin-top': '%value' }
            }
        });
    });

    var doAct = function (value) {
        editor.formatter.apply('margintop', { value: value });
        editor.fire('change', {});
    };
    
    editor.ui.registry.addMenuButton('margintopselect', {
        text: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><image width="24" height="24" x="0" y="0"'+
        	'href="'+
	        'AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElN'+
	        'RQfjBwMSLA49uoHFAAAAaElEQVQ4y2P8z4AdiLIzTGZgZMh5/ROHgv9YoYiUyDGR/yL/RY6LSGNX'+
	        'gV2blcgzkf9Q+EzEGpsaJiyOzGDYzyAJ50oy7BPNwFTFiMuPhAATmfrI18goQqZbybdx6ATOaKgO'+
	        'D430jw4Ax3tB6/sj81cAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDctMDNUMTA6NDQ6MTQrMDg6'+
	        'MDBuiBxaAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTA3LTAzVDEwOjQ0OjE0KzA4OjAwH9Wk5gAA'+
	        'AABJRU5ErkJggg==" /></svg>',
        tooltip: pluginName,
        fetch: function(callback) {
            var dom = editor.dom;
            var blocks = editor.selection.getSelectedBlocks();
            var lhv = 0;
            global$1.each(blocks, function(block) {
                if(lhv==0){
                    lhv = dom.getStyle(block,'margin-top') ? dom.getStyle(block,'margin-top') : 0;
                }
            });

            var items = margintop_val.split(' ').map(function(item){
                var text = item;
                var value = item;
                return {
                    type: 'togglemenuitem',
                    text: text,
                    active : lhv==value ? true :false,
                    onAction: function() {
                        doAct(value);
                    }
                };
            });
            callback(items);
        }
    });

    return {
        getMetadata: function () {
            return  {
                name: pluginName,
                url: "http://tinymce.ax-z.cn/more-plugins/lineheight.php",
            };
        }
    };
});
